package com.nabi.starter.common.tool;

/**
 * @author CAOYOU
 * @Title: UserAgent
 * @date 2019/9/3011:43
 */
public class UserAgent {
    private String system;
    private String browser;

    public UserAgent(String userAgent) {
        if (userAgent == "" || userAgent == null) {
            userAgent = "";
        }
        if (userAgent.contains("Windows")) {
            if (userAgent.contains("Windows NT 10.0")) {
                system = "Windows 10";
            } else if (userAgent.contains("Windows NT 6.2")) {
                system = "Windows 8";
            } else if (userAgent.contains("Windows NT 6.1")) {
                system = "Windows 7";
            } else if (userAgent.contains("Windows NT 6.0")) {
                system = "Windows Vista";
            } else if (userAgent.contains("Windows NT 5.2")) {
                system = "Windows XP";
            } else if (userAgent.contains("Windows NT 5.1")) {
                system = "Windows XP";
            } else if (userAgent.contains("Windows NT 5.01")) {
                system = "Windows 2000";
            } else if (userAgent.contains("Windows NT 5.0")) {
                system = "Windows 2000";
            } else if (userAgent.contains("Windows NT 4.0")) {
                system = "Windows NT 4.0";
            } else if (userAgent.contains("Windows 98; Win 9x 4.90")) {
                system = "Windows ME";
            } else if (userAgent.contains("Windows 98")) {
                system = "Windows 98";
            } else if (userAgent.contains("Windows 95")) {
                system = "Windows 95";
            } else if (userAgent.contains("Windows CE")) {
                system = "Windows CE";
            }
        } else if (userAgent.contains("Mac OS X")) {
            if (userAgent.contains("iPhone")) {
                system = "iPhone";
            } else if (userAgent.contains("iPad")) {
                system = "iPad";//判断系统
            } else {
                system = "Mac";//判断系统
            }
        } else if (userAgent.contains("Android")) {
            system = "Android";//判断系统
        } else if (userAgent.contains("Linux")) {
            system = "Linux";//判断系统
        } else if (userAgent.contains("FreeBSD")) {
            system = "FreeBSD";//判断系统
        } else if (userAgent.contains("Solaris")) {
            system = "Solaris";//判断系统
        }

        if (userAgent.contains("Edge")) {
            browser = "Microsoft Edge";
        } else if (userAgent.contains("QQBrowser")) {
            browser = "腾讯浏览器";
        } else if (userAgent.contains("Chrome") && userAgent.contains("Safari")) {
            browser = "Chrome";
        } else if (userAgent.contains("Firefox")) {
            browser = "Firefox";
        } else if (userAgent.contains("360")) {//Internet Explorer 6
            browser = "360浏览器";
        } else if (userAgent.contains("Opera")) {//Internet Explorer 6
            browser = "Opera";
        } else if (userAgent.contains("Safari") && !userAgent.contains("Chrome")) {
            browser = "Safari";
        } else if (userAgent.contains("MetaSr1.0")) {//Internet Explorer 6
            browser = "搜狗浏览器";
        } else if (userAgent.contains("TencentTraveler")) {//Internet Explorer 6
            browser = "腾讯浏览器";
        } else if (userAgent.contains("UC")) {//Internet Explorer 6
            browser = "UC浏览器";
        } else if (userAgent.contains("MSIE")) {
            if (userAgent.contains("MSIE 10.0")) {//Internet Explorer 10
                browser = "IE 10";
            } else if (userAgent.contains("MSIE 9.0")) {//Internet Explorer 9
                browser = "IE 9";
            } else if (userAgent.contains("MSIE 8.0")) {//Internet Explorer 8
                browser = "IE 8";
            } else if (userAgent.contains("MSIE 7.0")) {//Internet Explorer 7
                browser = "IE 7";
            } else if (userAgent.contains("MSIE 6.0")) {//Internet Explorer 6
                browser = "IE 6";
            }
        } else {//暂时支持以上三个主流.其它浏览器,待续...
            browser = "其他";
        }
    }

    public String getBrowser() {
        return browser;
    }

    public String getSystem() {
        return system;
    }
}
